
///Panel VAR
//16 countries
//All values are real using CPI 2010=100

save "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta", replace
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",

///Panel VAR model


xtset id year
gen lns=ln(share)
replace lns=0 if lns==.
zandrews lns
edit 

/////Model estimation


clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",

gen lnp=ln(price)
gen lns=ln(share)
replace lns=0 if lns==.
gen lngd=ln(gdp)
gen lnol=ln(olp)
gen lnft=ln(ft)
gen lnth5=ln(th5)

xtset id year

gen lns1=1/lns
replace lns1=0 if lns1==.

pvarsoc lns1 lnp
pvar dlns dlnp,   vce (cluster id) lags (4) exo ( dgd dol dft  dum )
pvargranger

pvarstable, graph

pvarirf, oirf mc(200) byoption(yrescale) porder(lnp lns)

pvarfevd, mc(200) porder(lnp lns) save("fevd_ci.dta")








//lag order selection

pvarsoc lns lnp , pvaropts(instlags(1/4))


gen dlns=d.lns
gen dlnp= d.lnp
gen dgd=d.lngd
gen dol=d.lnol
gen dft=d.lnft


////Model inverse of stock to use ratio

gen lns1=1/lns
replace lns1=0 if lns1==.

gen dlns1=d.lns1


pvar dlns1 dlnp, fod lags(3) instlags(1/4)  exo (lngd lnol lnft  dum )
esttab using first2.rtf, b(a2) se (2) starlevels (* 0.10 ** 0.05 *** 0.01) replace label nogap onecell

pvargranger


xtunitroot ht lns
xtunitroot ht lnp


pvarstable, graph



///Argentina

clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",

keep if country=="Argentina"

dfgls lnp
dfgls lns

varsoc lnp lns

drop dlnp dlns

gen dlnp= d.lnp
gen dlns= d.lns

gen lnth=ln(th5)
gen dlnt=d.lnth



var lns lnp , lags(1/2) exo(dgd dol dft)
vargranger

varlmar, mlag(2)
varnorm, jbera
varstable, graph


///Bangladesh

clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Bangladesh"

tsset year
dfgls lnp
dfgls lns

varsoc lnp lns

drop dlnp dlns

gen dlnp= d.lnp
gen dlns= d.lns


var lns lnp, lags(1/2) exo(dgd dol dft)
vargranger

varlmar, mlag(2)
varnorm, jbera
varstable, graph


///Brazil

clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Brazil"

dfgls lnp
dfgls lns

varsoc lnp lns

drop dlnp dlns

gen lnth=ln(th5)
gen dlnt=d.lnth


gen dlnp= d.lnp
gen dlns= d.lns
gen dth=d.lnth


var lns lnp, lags(1/2) exo(dgd dol dft)
vargranger

varlmar, mlag(2)
varnorm, jbera
varstable, graph




///Cambodia

clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Cambodia"

dfgls lnp
dfgls lns

dfgls d.lnp
dfgls d.lns



varsoc lnp lns

drop dlnp dlns

gen dlnp= d.lnp
gen dlns= d.lns


var dlns dlnp, lags(1/2) exo(dgd dol dft)
vargranger

varlmar, mlag(2)
varnorm, jbera
varstable, graph


///China
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="China"

dfgls lnp
dfgls d.lns


drop dlnp dlns

gen dlnp= d.lnp
gen dlns= d.lns

dfgls d.lnp
dfgls d.lns

varsoc lnp lns

var dlns dlnp, lags(1/2) exo(dgd dol dft)
vargranger

varlmar, mlag(2)
varnorm, jbera
varstable, graph



///India
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="India"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/4) exo(dgd dol dft)
vargranger

varlmar, mlag(4)
varnorm, jbera
varstable, graph


///Indonesia
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Indonesia"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/2) exo(dgd dol dft)
vargranger

varlmar, mlag(2)
varnorm, jbera
varstable, graph


///Japan
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Japan"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/1) exo(dgd dol dft)
vargranger

varlmar, mlag(1)
varnorm, jbera
varstable, graph


///Nigeria
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Nigeria"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/4) exo(dgd dol dft)
vargranger

varlmar, mlag(4)
varnorm, jbera
varstable, graph

///Pakistan
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Pakistan"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/1) exo(dgd dol dft)
vargranger

varlmar, mlag(1)
varnorm, jbera
varstable, graph



///Philippines
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Philippines"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/1) exo(dgd dol dft)
vargranger

varlmar, mlag(1)
varnorm, jbera
varstable, graph


///Skorea
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Skorea"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/2) exo(dgd dol dft)
vargranger

varlmar, mlag(2)
varnorm, jbera
varstable, graph


///Thailand
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Thailand"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/1) exo(dgd dol dft)
vargranger

varlmar, mlag(1)
varnorm, jbera
varstable, graph



///United States
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="United States"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/2) exo(dgd dol dft)
vargranger

varlmar, mlag(2)
varnorm, jbera
varstable, graph

///Uruguay
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Uruguay"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var lns lnp, lags(1/4) exo(dgd dol dft)
vargranger

varlmar, mlag(4)
varnorm, jbera
varstable, graph

///Vietnam
clear
use "C:\Users\mottaleb\Documents\stockpap\New2024\stock1.dta",
tab country
keep if country=="Vietnam"

drop dlnp dlns


dfgls lnp
dfgls lns
dfgls d.lnp
dfgls d.lns


varsoc lnp lns

gen dlnp= d.lnp
gen dlns= d.lns



var dlns dlnp, lags(1/1) exo(dgd dol dft)
vargranger

varlmar, mlag(1)
varnorm, jbera
varstable, graph




keep if country=="Pakistan"
keep if country=="Thailand"
keep if country=="Vietnam"
keep if country=="United States"
keep if country=="Argentina"
keep if country=="Brazil"
keep if country=="Uruguya"


zandrews lns if country=="Bangladesh"


zandrews lns if country=="China"
zandrews lns if country=="India"
zandrews lns if country=="Pakistan"
zandrews lns if country=="Thailand"
zandrews lns if country=="United States"
zandrews lns if country=="Vietnam"



////test for first difference

dfgls lnp

pvar lns lnp, lags (3) gmmstyle